//
//  WPVocalConvertViewController.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/5.
//  Copyright © 2016年 WPJoe. All rights reserved.
//

#import "WPVocalConvertViewController.h"
#import "WPNewsDealingTableViewCell.h"
#import "WPNewsPreheatTableViewCell.h"
#import "WPTradeListViewController.h"
#import "WPTradeDetailViewController.h"


static CGFloat timerInterval = 4.0;
static NSInteger sortBtnTag = 300;
@interface WPVocalConvertViewController ()<UIScrollViewDelegate, UITableViewDataSource, UITableViewDelegate>{
    NSMutableArray *_iamgeViews;/**< 存储图片视图 */
    NSMutableArray *_imageNames;/**< 存储图片名字 */
    NSMutableArray * _imageLabels;/**< 存储图片上的文本数组 */
    NSMutableArray * _imageLabelText;/**< 图片上显示的文本 */
    NSMutableArray * _urlImageNames;/**< 网络图片名字 */
}
@property (nonatomic, strong) UIView * FirstHeadView;/**< 第一组头部视图 */
@property (nonatomic, strong) UIScrollView * imageScrollView;/**< 轮播视图 */
@property (nonatomic, strong) UIPageControl * pageControl;/**< 分页显示器 */
@property (nonatomic, strong) NSTimer * timer;/**< 计时器 */

@property (nonatomic, strong) NSMutableArray * sortBtnArr;/**< 排序按钮数组 */
@property (nonatomic, strong) UITableView * latestTableView;/**< 最新信息表格视图 */
@property (nonatomic, strong) UIView * footView;/**< 表尾 */
@property (nonatomic, strong) UIView * headView;/**< 表头 */
@property (nonatomic, strong) NSMutableArray * latestArr;/**< 数据源 */
@property (nonatomic, strong) NSArray * detailImageNames;/**< 详情图片数组 */

- (void)initializeDataSource; /**< 初始化数据源 */
- (void)initializeUserInterface; /**< 初始化用户界面 */
- (void)refreshData;/**< 刷新数据 */
- (void)insertImageViewInScroll;/**< 在滚动视图中插入3个图片视图 */
- (void)insertImageInImageView;/**< 在图片视图上显示图片 */
- (void)configSortBtn;/**< 配置排序按钮 */
@end

@implementation WPVocalConvertViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeDataSource];
    [self initializeUserInterface];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.timer.fireDate = [NSDate distantPast];
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    //暂停timer
    [self.timer setFireDate:[NSDate distantFuture]];
}
#pragma mark - init
- (void)initializeDataSource {
self.detailImageNames = @[@"rain项目详情", @"迪斯尼项目详情", @"bigbang项目详情", @"iosyqsy"];
    _imageNames = [NSMutableArray arrayWithArray:@[@"banner1.png", @"banner2.png", @"banner3.png"]];
    self.latestArr = [NSMutableArray arrayWithCapacity:0];
    _imageLabelText = [NSMutableArray arrayWithObjects:@"王者归来Rain2016“THE SQUALL亚洲巡演-震撼袭蓉”", @"BIGBANG “WORLDTOUR[MADE]”亚洲巡演-即将来袭", @"上海迪士尼乐园6月16震撼开园", nil];
    _imageNames = [NSMutableArray arrayWithArray:@[@"banner1.png", @"banner2.png", @"banner3.png"]];
    WPNewsPreheatModel * model = [WPNewsPreheatModel new];
    model.image = @"image1";
    model.name = @"BIGBANG “WORLDTOUR[MADE]” 亚洲巡演";
    model.detailDescriiption = @"BIGBANG五人全体三巡首站上海.南京.深圳.北京.广州.天津.武汉.厦门.西安···入伍前全体最后一次巡演...";
    model.involvementNumber = @(28);
    NSString * bigbangTime = @"20160616";
    NSString * disiniTime = @"20160701";
    NSString * rainTime = @"20160423";
    NSString * yqsyTime = @"20160428";
    NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat = @"yyyyMMdd";
    NSDate * date = [formatter dateFromString:bigbangTime];
    NSDate * disiniDate = [formatter dateFromString:disiniTime];
    NSDate * rainDate = [formatter dateFromString:rainTime];
    NSDate * yqsyDate = [formatter dateFromString:yqsyTime];
    NSTimeInterval bigBangInterval = [date timeIntervalSince1970];
    NSTimeInterval disiniInterval = [disiniDate timeIntervalSince1970];
    NSTimeInterval rainInterval = [rainDate timeIntervalSince1970];
    NSTimeInterval yqsyInterval = [yqsyDate timeIntervalSince1970];
    model.endDate = @(bigBangInterval*1000);
    WPNewsPreheatModel * model1 = [WPNewsPreheatModel new];
    model1.image = @"image2";
    model1.name = @"上海迪斯尼乐园6月16日开园庆典";
    model1.detailDescriiption = @"作为中国大陆首座迪尼斯主题乐园，上海迪尼斯乐园将为游客提供无限可能，创造值得珍藏一生的回忆...";
    model1.involvementNumber = @(36);
    model1.endDate = @(disiniInterval*1000);
    WPNewsPreheatModel * model3 = [WPNewsPreheatModel new];
    NSDictionary * dic3 = [[NSDictionary alloc]initWithObjects:@[@"2016 岁月友情演唱会-成都站", @"郑伊健、陈小春、谢天华、林晓峰、钱嘉乐--经典不可复制的兄弟情！", @"youqingsuiy_sy.png", @(45), @(yqsyInterval*1000)] forKeys:@[@"name", @"detailDescriiption",@"image" ,@"involvementNumber", @"endDate"]];
    [model3 setValuesForKeysWithDictionary:dic3];
    
    WPNewsDealingModel * model2 = [WPNewsDealingModel new];
    model2.posterImageName = @"image3";
    model2.title = @"“The squall” Rain亚洲演唱会";
    model2.detail = @"2016“The Squall”王者归来Rain亚洲巡回演唱会-成都站。喊了那么久，终于Rain来了!迎风...";
    model2.ticketCount = @"12";
    model2.allTicketCount = @"30";
    model2.joinCount = @"42";
    model2.leftDays = @(rainInterval*1000);
    [_latestArr addObject:model2];
    [_latestArr addObject:model1];
    [_latestArr addObject:model];
    [_latestArr addObject:model3];
}
- (void)initializeUserInterface {
    [self.view addSubview:self.latestTableView];
    [_latestTableView.header beginRefreshing];
}
#pragma mark - responds events
- (void)respondsToImageViewTap {
    
}
- (void)respondsToTimer {
    [self.imageScrollView setContentOffset:CGPointMake(2*CGRectGetWidth(self.view.bounds), 0) animated:YES];
}
- (void)respondstOSortBtn:(UIButton *)sender {
    for (UIButton * btn in _sortBtnArr) {
        btn.selected = NO;
    }
    sender.selected = YES;
}
#pragma mark - 刷新数据
- (void)refreshData {
    if (_latestTableView.header.isRefreshing) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [_latestTableView.header endRefreshing];
        });
    }
    if (_latestTableView.footer.isRefreshing) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [_latestTableView.footer noticeNoMoreData];
        });
    }
}
#pragma mark - 协议UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _latestArr.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section != 0) {
        WPNewsPreheatTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        if (!cell) {
            cell = [[WPNewsPreheatTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"123"];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryNone;
        [cell setModelWithModel:_latestArr[indexPath.section]];
        return cell;
    }
    WPNewsDealingTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell) {
        cell = [[WPNewsDealingTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"1234"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryNone;
    [cell setModelWithModel:_latestArr[indexPath.section]];
    return cell;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}
//设置每一行高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 280*DHFlexibleHorizontalMutiplier();
}
//用户点击了某一行
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        WPTradeListViewController * vc = [WPTradeListViewController new];
        vc.model = _latestArr[indexPath.section];
        [self pushToNextController:vc withVCTitle:@"交易期"];
    } else {
        WPTradeDetailViewController * detailVC = [WPTradeDetailViewController new];
        detailVC.imageName = _detailImageNames[indexPath.section];
        [self pushToNextController:detailVC withVCTitle:@"项目详情"];
    }}

#pragma mark - 滚动视图协议
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == _latestTableView) {
        return;
    }
    //往右滑
    if (scrollView.contentOffset.x >= 2*CGRectGetWidth(self.view.bounds)) {
        if (_urlImageNames.count) {
            NSString *firstImage = [_urlImageNames.firstObject mutableCopy];
            NSString * firstText = [_imageLabelText.firstObject mutableCopy];
            [_urlImageNames removeObjectAtIndex:0];
            [_imageLabelText removeObjectAtIndex:0];
            [_urlImageNames addObject:firstImage];
            [_imageLabelText addObject:firstText];
            self.pageControl.currentPage = self.pageControl.currentPage == _urlImageNames.count - 1? 0:self.pageControl.currentPage+1;
        } else {
            NSString *firstImage = [_imageNames.firstObject mutableCopy];
            NSString * firstText = [_imageLabelText.firstObject mutableCopy];
            [_imageNames removeObjectAtIndex:0];
            [_imageLabelText removeObjectAtIndex:0];
            [_imageNames addObject:firstImage];
            [_imageLabelText addObject:firstText];
            self.pageControl.currentPage = self.pageControl.currentPage == _imageNames.count - 1? 0:self.pageControl.currentPage+1;
        }
    }
    //往左滑
    else if (scrollView.contentOffset.x <= 0) {
        if (_urlImageNames.count) {
            NSString *lastImage = [_urlImageNames.lastObject mutableCopy];
            NSString * lastText = [_imageLabelText.lastObject mutableCopy];
            [_urlImageNames removeObjectAtIndex:_urlImageNames.count - 1];
            [_imageLabelText removeObjectAtIndex:_imageLabelText.count - 1];
            [_urlImageNames insertObject:lastImage atIndex:0];
            [_imageLabelText insertObject:lastText atIndex:0];
            self.pageControl.currentPage = self.pageControl.currentPage == 0? _urlImageNames.count - 1:self.pageControl.currentPage-1;
        } else {
            NSString *lastImage = [_imageNames.lastObject mutableCopy];
            NSString * lastText = [_imageLabelText.lastObject mutableCopy];
            [_imageNames removeObjectAtIndex:_imageNames.count - 1];
            [_imageLabelText removeObjectAtIndex:_imageLabelText.count - 1];
            [_imageNames insertObject:lastImage atIndex:0];
            [_imageLabelText insertObject:lastText atIndex:0];
            self.pageControl.currentPage = self.pageControl.currentPage == 0? _imageNames.count - 1:self.pageControl.currentPage-1;
        }
    }else {
        //停在中间
        return;
    }
    [self insertImageInImageView];
    //更新偏移量
    scrollView.contentOffset = CGPointMake(CGRectGetWidth(scrollView.bounds), 0);
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    //暂停timer
    if (scrollView == _latestTableView) {
        return;
    }
    _timer.fireDate = [NSDate distantFuture];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    //从结束拖动开始计算延迟2s再启动
    if (scrollView == _latestTableView) {
        return;
    }
    _timer.fireDate = [NSDate dateWithTimeIntervalSinceNow:timerInterval];
}
#pragma mark - private methods
- (void)insertImageViewInScroll {
    _iamgeViews = [NSMutableArray arrayWithCapacity:0];
    _imageLabels = [NSMutableArray arrayWithCapacity:0];
    for (int i = 0; i < 3; i++) {
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(i*SCREEN_SIZE.width, 0, SCREEN_SIZE.width, CGRectGetHeight(self.imageScrollView.bounds))];
        UIView * clearView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(imageView.frame)-40*DHFlexibleHorizontalMutiplier(), SCREEN_SIZE.width, 40*DHFlexibleHorizontalMutiplier())];
        clearView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.2];
        UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), 0, 200*DHFlexibleHorizontalMutiplier(), 40*DHFlexibleHorizontalMutiplier())];
        lab.textColor = [UIColor whiteColor];
        lab.backgroundColor =[UIColor clearColor];
        lab.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
        [clearView addSubview:lab];
        [imageView addSubview:clearView];
        imageView.userInteractionEnabled = YES;
        UITapGestureRecognizer * tapges = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(respondsToImageViewTap)];
        [imageView addGestureRecognizer:tapges];
        [_imageScrollView addSubview:imageView];
        //将图片视图植入——imageViews 便于便利数组
        [_iamgeViews addObject:imageView];
        [_imageLabels addObject:lab];
    }
}
- (void)insertImageInImageView {
    NSInteger index = 0;
    for (UIImageView *imageView in _iamgeViews) {
        if (_urlImageNames.count) {
            index = index == _urlImageNames.count ? _urlImageNames.count - 1:index;
            NSURL * imageUrl = [NSURL URLWithString:_urlImageNames[index]];
            UIImage * placeImge = imageView.image;
            [imageView sd_setImageWithURL:imageUrl placeholderImage:placeImge];
        } else {
            imageView.image = IMAGE_NAME(_imageNames[index]);
        }
        UILabel * lab = _imageLabels[index];
        lab.text = _imageLabelText[index];
        index++;
    }
}
- (void)configSortBtn {
    NSArray * btnTitles = @[@"预热期", @"预售期", @"交易期", @"最新上架", @"支持最多", @"关注最多"];
    self.sortBtnArr = [NSMutableArray arrayWithCapacity:0];
    for (int i = 0; i < btnTitles.count; i++) {
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.bounds = CGRectMake(0, 0, 90*DHFlexibleHorizontalMutiplier(), 25*DHFlexibleHorizontalMutiplier());
        btn.center = CGPointMake((55 + i % 3 * 105)*DHFlexibleHorizontalMutiplier(), (i / 3 *36 +18)*DHFlexibleHorizontalMutiplier()+CGRectGetMaxY(_imageScrollView.frame)+10*DHFlexibleHorizontalMutiplier());
        [btn setTitle:btnTitles[i] forState:UIControlStateNormal];
        [btn setTitleColor:COLOR_RGB(211, 211, 211, 1) forState:UIControlStateNormal];
        [btn setTitleColor:COLOR_RGB(234, 0, 30, 1) forState:UIControlStateSelected];
        btn.titleLabel.font = [UIFont systemFontOfSize:13*DHFlexibleHorizontalMutiplier()];
        btn.tag = sortBtnTag + i;
        btn.layer.borderWidth = 1;
        btn.layer.borderColor = COLOR_RGB(211, 211, 211, 1).CGColor;
        btn.layer.cornerRadius = 12.5*DHFlexibleHorizontalMutiplier();
        [btn addTarget:self action:@selector(respondstOSortBtn:) forControlEvents:UIControlEventTouchUpInside];
        [_sortBtnArr addObject:btn];
        [self.FirstHeadView addSubview:btn];
    }
    
}
#pragma mark - getter
//- (UIScrollView *)backScrollView {
//    if (!_backScrollView) {
//        _backScrollView = ({
//            UIScrollView * view = [[UIScrollView alloc]initWithFrame:CGRectMake(0, navBar_Fheight, SCREEN_SIZE.width, SCREEN_SIZE.height - navBar_Fheight)];
//            view.showsVerticalScrollIndicator = NO;
//            view.backgroundColor = [UIColor whiteColor];
//            view.directionalLockEnabled = YES;
//            view.contentSize = CGSizeMake(0, 1450*DHFlexibleHorizontalMutiplier());
//            view;
//        });
//    }
//    return _backScrollView;
//}
- (UIView *)FirstHeadView {
    if (!_FirstHeadView) {
        _FirstHeadView = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_SIZE.width, 220*DHFlexibleHorizontalMutiplier())];
            [view addSubview:self.imageScrollView];
            [view addSubview:self.pageControl];
            [self insertImageViewInScroll];
            [self insertImageInImageView];
            [view addSubview:self.headView];
            view;
        });
    }
    return _FirstHeadView;
}
- (UIScrollView *)imageScrollView {
    if (!_imageScrollView) {
        _imageScrollView = ({
            UIScrollView * view = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_SIZE.width, 170*DHFlexibleHorizontalMutiplier())];
            view.showsHorizontalScrollIndicator = NO;
            view.showsVerticalScrollIndicator = NO;
            view.pagingEnabled = YES;
            view.bounces = NO;
            view.delegate = self;
            view.contentSize = CGSizeMake(CGRectGetWidth(self.view.frame)*3, 0);
            view.contentOffset = CGPointMake(CGRectGetWidth(view.bounds), 0);
            view;
        });
    }
    return _imageScrollView;
}
- (UIPageControl *)pageControl {
    if (!_pageControl) {
        _pageControl = ({
            UIPageControl * control = [[UIPageControl alloc]initWithFrame:CGRectMake(250*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.imageScrollView.frame) - 40*DHFlexibleHorizontalMutiplier(), 50*DHFlexibleHorizontalMutiplier(), 40*DHFlexibleHorizontalMutiplier())];
            control.numberOfPages = _imageNames.count;
            control.currentPage = 0;
            control.hidesForSinglePage = YES;
            control.pageIndicatorTintColor = COLOR_RGB(230, 231, 232, 1);
            control.currentPageIndicatorTintColor = COLOR_RGB(140, 141, 145, 1);
            control;
        });
    }
    return _pageControl;
}

- (NSTimer *)timer {
    if (!_timer) {
        _timer = [NSTimer scheduledTimerWithTimeInterval:timerInterval target:self selector:@selector(respondsToTimer) userInfo:nil repeats:YES];
    }
    return _timer;
}
- (UIView *)headView {
    if (!_headView) {
        _headView = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.imageScrollView.frame), SCREEN_SIZE.width, 50*DHFlexibleHorizontalMutiplier())];
            UIView * spera = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_SIZE.width, 10*DHFlexibleHorizontalMutiplier())];
            spera.backgroundColor = COLOR_RGB(241, 241, 241, 1);
            [view addSubview:spera];
            UILabel * zhTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 15*DHFlexibleHorizontalMutiplier(), SCREEN_SIZE.width, 20*DHFlexibleHorizontalMutiplier())];
            zhTitle.textAlignment = NSTextAlignmentCenter;
            zhTitle.font = [UIFont boldSystemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            zhTitle.textColor = COLOR_RGB(61, 61, 61, 1);
            zhTitle.text = @"最新上架";
            [view addSubview:zhTitle];
            UILabel * enTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 30*DHFlexibleHorizontalMutiplier(), SCREEN_SIZE.width, 15*DHFlexibleHorizontalMutiplier())];
            enTitle.textAlignment = NSTextAlignmentCenter;
            enTitle.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            enTitle.textColor = COLOR_RGB(153, 153, 153, 1);
            enTitle.text = @"The new arrival";
            [view addSubview:enTitle];
            UIView * leftLine = [[UIView alloc]initWithFrame:CGRectMake(60*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(zhTitle.frame), 40*DHFlexibleHorizontalMutiplier(), 1)];
            leftLine.backgroundColor = COLOR_RGB(234, 27, 47, 1);
            UIView * rightLine = [[UIView alloc]initWithFrame:CGRectMake(220*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(zhTitle.frame), 40*DHFlexibleHorizontalMutiplier(), 1)];
            rightLine.backgroundColor = COLOR_RGB(234, 27, 47, 1);
            [view addSubview:leftLine];
            [view addSubview:rightLine];
            view;
        });
    }
    return _headView;
}
- (UIView *)footView {
    if (!_footView) {
        _footView = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_SIZE.width, 70*DHFlexibleHorizontalMutiplier())];
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 20*DHFlexibleHorizontalMutiplier(), SCREEN_SIZE.width, 30*DHFlexibleHorizontalMutiplier())];
            lab.textAlignment = NSTextAlignmentCenter;
            lab.textColor = COLOR_RGB(141, 141, 141, 1);
            lab.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            lab.text = @"没有更多数据啦";
            [view addSubview:lab];
            view;
        });
    }
    return _footView;
}
- (UITableView *)latestTableView {
    if (!_latestTableView) {
        _latestTableView = ({
            UITableView * tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, navBar_Fheight, SCREEN_SIZE.width, SCREEN_SIZE.height - navBar_Fheight) style:UITableViewStyleGrouped];
            tableview.dataSource = self;
            tableview.delegate = self;
            tableview.tableHeaderView = self.FirstHeadView;
            tableview.tableFooterView = [UIView new];
            tableview.pagingEnabled = NO;
            tableview.bounces = YES;
            tableview.separatorColor = [UIColor clearColor];
            tableview.backgroundColor = [UIColor whiteColor];
            __weak typeof(self)weakself = self;
            tableview.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
                [weakself refreshData];
            }];
            tableview.footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
                [weakself refreshData];
            }];
            tableview;
        });
    }
    return _latestTableView;
}
@end
